﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml;

namespace ShellAnywhere.Model
{
	public class TargetList : List<ITarget>, IList<ITarget>, IXmlSerializable
	{
		#region ctors
		public TargetList() : base() { }
		public TargetList(IEnumerable<ITarget> collection) : base(collection) { }
		public TargetList(int capacity) : base(capacity) { }
		#endregion ctors

		#region props
		[XmlAttribute]
		public string Name { get; set; }
		#endregion props

		#region methods
		public XmlSchema GetSchema() { return null; }
		public XmlSerializer GetLinkSerializer() { return new XmlSerializer(typeof(Target)); }
		public void ReadXml(XmlReader reader)
		{
			XmlSerializer ls = GetLinkSerializer();
			reader.ReadStartElement();
			{
				while (ls.CanDeserialize(reader))
				{
					Add(ls.Deserialize(reader) as ITarget);
					reader.ReadStartElement();
				}
			}
			reader.ReadEndElement();
		}
		public void WriteXml(XmlWriter writer)
		{
			XmlSerializer ls = GetLinkSerializer();
			foreach (ITarget item in this)
				ls.Serialize(writer, item);
		}
		public List<IParam> ToParamList()
		{
			List<IParam> list = new List<IParam>();
			foreach (ITarget target in this)
				list.Add(target);
			return list;
		}
		#endregion methods
	}
}
